<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>叮铃当啷管理系统</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta http-equiv="Access-Control-Allow-Origin" content="*">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<meta http-equiv="Cache-Control" content="no-siteapp">
		<link rel="icon" href="favicon.ico">
		<link rel="stylesheet" href="./layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="./css/index.css" media="all" />
	</head>

	<body class="main_body">
		<div class="layui-layout layui-layout-admin">
			<!-- 顶部 -->
			<div class="layui-header header">
				<div class="layui-main mag0">
					<a href="#" class="logo">叮铃当啷</a>
					<!-- 显示/隐藏菜单 -->
					<a href="javascript:;" class="seraph hideMenu icon-caidan"></a>
					<!-- 顶部右侧菜单 -->
					<ul class="layui-nav top_menu">
						<li class="layui-nav-item" pc>
							<a href="javascript:;" class="clearCache"><i class="layui-icon" data-icon="&#xe640;">&#xe640;</i><cite>清除缓存</cite><span class="layui-badge-dot"></span></a>
						</li>
						<li class="layui-nav-item lockcms" pc>
							<a href="javascript:;"><i class="seraph icon-lock"></i><cite>锁屏</cite></a>
						</li>
						<li class="layui-nav-item" id="userInfo">
							<a href="javascript:;">
								<!--<img src="images/face.jpg" class="layui-nav-img userAvatar" width="35" height="35">--><cite class="adminName"></cite>
							</a>
							<dl class="layui-nav-child">
								<!-- <dd>
								<a href="javascript:;" class="updatePwd" data-url=""><i class="seraph icon-xiugai" data-icon="icon-xiugai"></i><cite>修改密码</cite></a>
							</dd> -->
								<dd>
									<a href="javascript:;" class="updatePwd"><i class="seraph icon-xiugai" data-icon="icon-xiugai"></i><cite>修改密码</cite></a>
								</dd>
								<dd>
									<a href="javascript:;" class="signOut"><i class="seraph icon-tuichu"></i><cite>退出</cite></a>
								</dd>
							</dl>
						</li>
					</ul>
				</div>
			</div>
			<!-- 左侧导航 -->
			<div class="layui-side layui-bg-black">
				<!-- <div class="user-photo">
                <a class="img" title="我的头像" ><img src="images/face.jpg" class="userAvatar"></a>
                <p>你好！<span class="userName">驊驊龔頾</span>, 欢迎登录</p>
            </div>
            搜索
            <div class="layui-form component">
                <select name="search" id="search" lay-search lay-filter="searchPage">
                    <option value="">搜索页面或功能</option>
                    <option value="1">layer</option>
                    <option value="2">form</option>
                </select>
                <i class="layui-icon">&#xe615;</i>
            </div> -->
				<div class="navBar layui-side-scroll" id="navBar">
					<ul class="layui-nav layui-nav-tree">
						<li class="layui-nav-item layui-this">
							<a href="javascript:;" data-url="page/main.html"><i class="layui-icon" data-icon=""></i> <cite>后台首页</cite></a>
						</li>
						<!--<li class="layui-nav-item">
							<a><i class="layui-icon" data-icon=""></i><cite>系统管理</cite><span class="layui-nav-more"></span> </a>
							<dl class="layui-nav-child">
								<dd>
									<a data-url="./system/user/list.html"><i class="layui-icon" data-icon=""></i><cite>员工管理</cite></a>
								</dd>
								<dd>
									<a data-url="./system/department/list.html"><i class="layui-icon" data-icon=""></i><cite>部门管理</cite></a>
								</dd>
								<dd>
									<a data-url="./system/role/list.html"><i class="layui-icon" data-icon=""></i><cite>岗位管理</cite></a>
								</dd>
								<dd>
									<a data-url="./system/permission/list.html"><i class="layui-icon" data-icon=""></i><cite>权限管理</cite></a>
								</dd>
							</dl>
						</li>-->
					</ul>
				</div>
			</div>
			<!-- 右侧内容 -->
			<div class="layui-body layui-form">
				<div class="layui-tab mag0" lay-filter="bodyTab" id="top_tabs_box">
					<ul class="layui-tab-title top_tab" id="top_tabs">
						<li class="layui-this" lay-id=""><i class="layui-icon">&#xe68e;</i> <cite>后台首页</cite></li>
					</ul>
					<ul class="layui-nav closeBox">
						<li class="layui-nav-item">
							<a href="javascript:;"><i class="layui-icon caozuo">&#xe643;</i> 页面操作</a>
							<dl class="layui-nav-child">
								<dd>
									<a href="javascript:;" class="refresh refreshThis"><i class="layui-icon">&#x1002;</i> 刷新当前</a>
								</dd>
								<dd>
									<a href="javascript:;" class="closePageOther"><i class="seraph icon-prohibit"></i> 关闭其他</a>
								</dd>
								<dd>
									<a href="javascript:;" class="closePageAll"><i class="seraph icon-guanbi"></i> 关闭全部</a>
								</dd>
							</dl>
						</li>
					</ul>
					<div class="layui-tab-content clildFrame">
						<div class="layui-tab-item layui-show">
							<iframe src="./main.html"></iframe>
						</div>
					</div>
				</div>
			</div>
			<!-- 底部 -->
			<div class="layui-footer footer">
				<p>
					<span class="footer-span">copyright @2018 dingding</span>
				</p>
			</div>
		</div>

		<!-- 移动导航 -->
		<div class="site-tree-mobile">
			<i class="layui-icon">&#xe602;</i>
		</div>
		<div class="site-mobile-shade"></div>
		<div class="topay"></div>
		<script type="text/javascript" src="./js/jquery-2.1.1.min.js"></script>
		<script type="text/javascript" src="./layui/layui.js"></script>
		<script type="text/javascript" src="./custom/js/common.js"></script>
		<script type="text/javascript" src="./js/index.js"></script>
		<script type="text/javascript">
			layui.use(["element", 'form', 'layer'], function() {
				var layer = parent.layer === undefined ? layui.layer : parent.layer;
				var $ = layui.jquery;
				var getInfoApi = constant.baseUrl + "/getInfo";
				var logoutApi = constant.baseUrl + "/logout";
				var element = layui.element;
				//加载用户信息 
				if(cache.user.get()) {
					var user = JSON.parse(cache.user.get());
					$(".adminName").html(user.name);
					var permission = JSON.parse(cache.permission.get());
					filterMenu(permission);
				} else {
					// 从接口拿到用户信息
					loadAjax(getInfoApi, "get", null, function(response) {
						baseCallBack(response, function(response) {
							filterMenu(response.data.permission);
							cache.user.set(JSON.stringify(response.data.user));
							cache.permission.set(JSON.stringify(response.data.permission));
							$(".adminName").html(response.data.user.name);

						})
					});
				}

				$(".updatePwd").click(function() {
					openAreaLayer("修改密碼", "./updatePwd.html", "480px", "360px", true);
				})

				$(".signOut").click(function() {
					confirmLayer('提示信息', '确定退出？', function(confirm, index) {
						loadAjax(logoutApi, "get", null, function(response) {
							baseCallBack(response, function(response) {
								cache.cleanAll();
								location.href = "./login.html"
							})
						});
					})
				});

				$(".clearCache").click(function() {
					cache.clean();
					var index = layer.msg('清除缓存中，请稍候', {
						icon: 16,
						time: false,
						shade: 0.8
					});
					setTimeout(function() {
						layer.close(index);
						layer.msg("缓存清除成功！");
					}, 1000);
				})
				//过滤权限
				function filterMenu(permissions) {
					if(permissions) {
						var permissionCodeArray = new Array();
						var menuTree = new Array();
						for(permission of permissions) {
							if(permission.type != 1) {
								//类型 1-显示菜单、2-跳转菜单、3-功能按钮
								//把权限码放到数组当中
								permissionCodeArray.push(permission.code);
							} else {
								getTree(permission, permissions);
								menuTree.push(permission);
							}
						}
						//加载菜单
						$(".layui-nav-tree").append(initMenu(menuTree));
						element.init();
						//存放缓存
						cache.code.set(permissionCodeArray);
					}
				}
				//根据菜单主键id生成菜单列表html
				//id：菜单主键id
				//arry：菜单数组信息
				function getTree(permission, permissions) {
					permission["child"] = new Array();
					for(child of permissions) {
						if(child.pid) {
							if(child.pid == permission.id && child.type != 3) {
								permission.child.push(child);
								getTree(child, permissions);
							}
						}
					}
				}

				function initMenu(permissions) {
					var str = "";
					for(permission of permissions) {
						str += '<li class="layui-nav-item"><a><i class="layui-icon ' + permission.icon + '"></i><cite>' + permission.name + '</cite><span class="layui-nav-more"></span> </a>';
						str += appendChild(permission);
						str += '</li>';
					}
					return str;
				}

				function appendChild(permission) {
					var str = "";
					if(permission.child) {
						str += '<dl class="layui-nav-child">';
						for(child of permission.child) {
							str += '<dd>';
							str += '<a data-url="page/'+ child.url + '"><i class="layui-icon ' + child.icon + '"></i><cite>' + child.name + '</cite></a>';
							str += '</dd>';
						}
						str += '</dl>';
					}
					return str;
				}

			});
		</script>
	</body>

</html>